package cn.itcast.hiss.server.order;

import cn.itcast.hiss.server.mapper.OrderMapper;
import cn.itcast.hiss.server.util.SpringContextHolder;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.springframework.context.ApplicationContext;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

/*
 * 统计订单信息
 **/
public class OrderServiceTask implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution) {
        ApplicationContext applicationContext = SpringContextHolder.getApplicationContext();
        OrderMapper orderMapper = applicationContext.getBean(OrderMapper.class);
        List<Map<String, Double>> amount = orderMapper.getAmount();
        String emailContent = amount.toString();
        String title = "订单销售额日报"+ LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        execution.setVariable("emailContent",emailContent);
        execution.setVariable("emailTitle",title);
    }

}
